#pragma once
#include"RBtree.h"
namespace ly {
	template<class Key,class Value>
	class map {
	public:
		struct Keyoft {
			const Key& operator()(const pair<const Key, Value>& a) {
				return a.first;
			}
		};
		//typedef ly::Node<pair<const Key, Value>> Node;
		//typedef ly::iterator<pair<const Key, Value>> iterator;
		//typedef ly::iterator<pair<const Key, Value>> const_iterator;
		typedef typename rbtree<Key, pair<const Key, Value>, Keyoft>::iterator iterator;
		typedef typename rbtree<Key, pair<const Key, Value>, Keyoft>::const_iterator const_iterator;
		pair<iterator,bool> insert(Key k) {
			auto t = _root.insert({ k,Value()});
			bool ok = true;
			if (t == nullptr) {
				ok = false;
			}
			return { t, ok };
		}
		iterator begin() {
			return _root.begin();
		}
		iterator end() {
			return _root.end();
		}
		const_iterator begin() const {
			return _root.ConstBegin();
		}
		const_iterator end() const {
			return _root.ConstEnd();
		}
		iterator lower_bound(Key k) {
			return _root.lower_bound({ k,Value() });
		}
		iterator upper_bound(Key k) {
			return _root.upper_bound({ k,Value() });
		}
	private:
		ly::rbtree<const Key, pair<const Key, Value>, Keyoft> _root;
	};
}